<?php
include_once("../class_main_curl.php");
include_once("../functions.php");

$microtime = microtime(TRUE);
$curr_time = date("Y-m-d H:i:s");
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
echo "<HTML>[".$curr_time."]<BR />\n";
$vk_dir       = "/home/fox/dev/www/vk/reg/";
$temp_dir     = "temp-www/vk/";
$is_finished  = 0;

$fname_login  = "need_logins.txt";
$fname_pass   = "need_passwords.txt";
$fname_proxy  = "proxy.txt";

$fd           = fopen($fname_login, 'r');
$logins       = fread($fd, filesize($fname_login));
fclose($fd);
$logins       = split("\n", $logins);

$fd           = fopen($fname_pass, 'r');
$passes       = fread($fd, filesize($fname_pass));
fclose($fd);
$passes       = split("\n", $passes);

/*
$fd           = fopen($fname_proxy, 'r');
$proxies      = fread($fd, filesize($fname_proxy));
fclose($fd);
$proxies       = split("\n", $proxies);
*/

$obj_curl     = new main_curl();
//$obj_curl->proxy = "127.0.0.1:9050";


if(isset($_GET['sid']) && isset($_GET['code']) && isset($_GET['mu']) && isset($_GET['login']) && isset($_GET['reg_code'])) {
	$sid = $_GET['sid']; $code = $_GET['code']; $mu = $_GET['mu']; $login = $_GET['login']; $reg_code = $_GET['reg_code'];
	$first_name = get_random_string(7);
	$last_name  = get_random_string(9);
	$obj_curl->cookie    = $temp_dir."cookie-".$login.".txt";
	$obj_curl->filename  = $temp_dir."vk2-".$login.".html";
	$obj_curl->url       = "http://vkontakte.ru/profileEdit.php?page=education";
	$obj_curl->post      = "subm=1&sid=$sid&time=reg&code=$code&mu=$mu&first_name=$first_name&last_name=$last_name&email=".$logins[$login]."%40yandex.ru&pass=".$passes[$login]."&reg_code=$reg_code&country=1&uni_city=nil&other_city_name=%CD%E0%E7%E2%E0%ED%E8%E5+%E3%EE%F0%EE%E4%E0&other_university_name=%CD%E0%E7%E2%E0%ED%E8%E5+%E3%EE%F0%EE%E4%E0&other_faculty_name=%CD%E0%E7%E2%E0%ED%E8%E5+%F4%E0%EA%F3%EB%FC%F2%E5%F2%E0&other_chair_name=%CD%E0%E7%E2%E0%ED%E8%E5+%EA%E0%F4%E5%E4%F0%FB";
	//$obj_curl->proxy     = $proxies[$login];
	//$obj_curl->proxy     = "127.0.0.1:8118";
	$obj_curl->proxy     = FALSE;
	while(($obj_curl->method_main_curl()) === FALSE ) { echo "RESEND\n"; eflush(); }
	//if (tor_new_identity('127.0.0.1', '9051')) { echo "Identity switched!\n"; } else { echo "FUCK!\n"; }

	list($is_good_reg) = search_infile($obj_curl->filename, "<div style='text-align:left;'>", "<b>", "</b>", 2);
	$is_good_reg = to_utf($is_good_reg);

	if("$is_good_reg" == $logins[$login]."@yandex.ru") {
		echo substr($is_good_reg, 0, -10)." GOOD<br>\n";
	} else {
		list($is_good_reg) = search_infile($obj_curl->filename, "style='color:#A00", "center'>", "</p>");
		$is_good_reg = to_utf($is_good_reg);
		if("$is_good_reg" == "К сожалению, Вы указали неверный код.<br />Попробуйте ещё раз.") {
			echo $logins[$login]." BAD reg_code<br>\n";
			$login--;
		} else {
			echo $logins[$login]." XZ ERROR<BR>\n";
		}
	}
	if($login < (count($logins)-1)) { $login++; } else { $is_finished = 1; echo "FINISHED\n"; }
} else {
	$login=0;
	system("rm ".$temp_dir."*.txt"); system("rm ".$temp_dir."*.html");
	echo "1st time<BR>\n";
}

if($is_finished == 0) {
	$obj_curl->cookie    = $temp_dir."cookie-".$login.".txt";
	$obj_curl->filename  = $temp_dir."vk1-".$login.".html";
	$obj_curl->url       = "http://vkontakte.ru/reg0";
	$obj_curl->post      = FALSE;
	$obj_curl->proxy     = FALSE;
	//$obj_curl->proxy     = "127.0.0.1:8118";
	while(($obj_curl->method_main_curl()) === FALSE ) { echo "RESEND\n"; eflush(); }
	//list($captcha) = search_infile($obj_curl->filename, "captcha.php?sid=", "captcha.php?sid=", "\"/>");
	list($sid)     = search_infile($obj_curl->filename, "name=\"sid\"" , "value=\"", "\">");
	list($code)    = search_infile($obj_curl->filename, "name=\"code\"", "value=\"", "\">");
	list($mu)      = search_infile($obj_curl->filename, "name=\"mu\"", "value=\"", "\">");
	//file_put_contents($temp_dir."captcha-".$login.".jpg", file_get_contents("http://vkontakte.ru/captcha.php?sid=".$sid));
	$obj_curl->cookie    = $temp_dir."cookie2-".$login.".txt";
	$obj_curl->filename  = $temp_dir."captcha-".$login.".jpg";
	$obj_curl->url       = "http://vkontakte.ru/captcha.php?sid=".$sid;
	while(($obj_curl->method_main_curl()) === FALSE ) { echo "RESEND\n"; }
	
	echo "<BODY>"; 
	echo "<IMG SRC=\"".$temp_dir."captcha-".$login.".jpg\" /><br />\n";
	echo "<FORM action=\"http://vk/reg/reg_vk.php\" method=\"get\"><BR />\n";
	echo "<INPUT type=\"hidden\" name=\"login\" value=\"".$login."\">[".$login."] ".$logins[$login]." <BR />\n";
	echo "<INPUT type=\"hidden\" name=\"sid\" value=\"".$sid."\"><BR />\n";
	echo "<INPUT type=\"hidden\" name=\"code\" value=\"".$code."\"><BR />\n";
	echo "<INPUT type=\"hidden\" name=\"mu\" value=\"".$mu."\"><BR />\n";
	echo "<INPUT type=\"text\" name=\"reg_code\"><BR>\n";
	echo "<INPUT type=\"submit\" value=\"Send\">\n";
	echo "</FORM>\n";
?>  <script type="text/javascript">document.forms[0].reg_code.focus();</script><?php
	echo "</BODY>";
}
 
echo "</HTML>\n";

?>